<?php


namespace App\Http\Controllers\Admin\Sign;

use App\Http\Controllers\Admin\BaseAdminController;
use App\Models\Invite;
use App\Models\Signs;
use App\Models\Rules;
use Illuminate\Support\Facades\DB;

class SignsController extends BaseAdminController
{
    public function __construct()
    {
        parent::__construct();
    }

    public function index()
    {
        // 处理排序
        $sort = request('sort', 'id');
        $order = request('order', 'desc');
        $query = Signs::orderBy($sort, $order);
        // 取得列表
        $signs = $query->select([
            'id',
            'uid',
            'username',
            'scores',
            'created_at'
        ])->paginate(parent::PERPAGE);
        // 将查询参数拼接到分页链接中
        $signs->appends(app('request')->all());

        return view('admin.sign.signs', [
            'signs' => $signs,
        ]);
    }

    /**
     * 添加积分规则页面
     *
     * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
     * @author yh 20200327
     */
    public function add()
    {
        $user = Rules::first();
        return view('admin.sign.signs_form', ['user' => $user]);
    }

    /**
     * 添加积分规则页面
     *
     * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
     * @author yh 20200327
     */
    public function invite()
    {
        $user = Invite::first();
        return view('admin.sign.invite', ['user' => $user]);
    }

    /**
     *  邀请的积分设置表
     * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
     * @author yh 20200327
     */
    public function save_invite(){
        $score = request('score');
        $signRule =Invite::findOrNew(request('id'));
        $signRule->score = $score;
        $signRule->save();
        return $this->success();
    }
}